package com.qiantu.phone.utils;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qiantu.phone.bean.WeatherIconBean;

import java.util.List;

public class WeatherIconParseUtil {

    private static List<WeatherIconBean> mWeatherIcons;

    public static WeatherIconBean getIcon(Context context, int code) {
        if(mWeatherIcons == null){
            String jsonDataStr = new GetJsonDataUtil().getJson(context, "WeatherIcon.json");//获取assets目录下的json文件数据
            mWeatherIcons = new Gson().fromJson(jsonDataStr, new TypeToken<List<WeatherIconBean>>() {}.getType());
        }
        for(WeatherIconBean weatherIcon : mWeatherIcons){
            if(weatherIcon.getCode() == code){
                return weatherIcon;
            }
        }
        return null;
    }

    public static void clearData(){
        mWeatherIcons = null;
    }
}
